package org.study.user.web.login;

import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpRequest;
import org.springframework.web.bind.annotation.*;
import org.study.user.model.User;
import org.study.user.service.LoginService;

import javax.servlet.http.HttpSession;

@RestController
@RequestMapping("/user")
@Slf4j
public class LoginController {

    @Autowired
    LoginService loginService;
    @RequestMapping("/login")
    public String login(@RequestBody User user, HttpSession session){
        log.info("用户登录："+ JSON.toJSONString(user));
        if(loginService.login(user)){
            session.setAttribute("user",user);
            session.setMaxInactiveInterval(30*1000*60);
            return "1";
        }
        else {
            return "-1";
        }
    }
}
